package com.caesar.Date.convert_each;

import org.junit.jupiter.api.Test;

import java.util.Calendar;
import java.util.Date;

/**
 * @author caesar
 * @date 2025/7/15
 * @Description:第1代和第2代的转换
 * @apiNote
 */
public class TestOneTwo {
    @Test
    public void test(){
        Date d = new Date();
        Calendar c = Calendar.getInstance();
        c.setTime(d);//设置时间为 d对象的时间
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH) + 1;
        int day = c.get(Calendar.DAY_OF_MONTH);

        int hour = c.get(Calendar.HOUR_OF_DAY);
        int minute = c.get(Calendar.MINUTE);
        System.out.println(year +"年" + month + "月" + day + "日 " + hour + ":" + minute);
    }

    @Test
    public void test2(){
        Calendar c = Calendar.getInstance();
        Date d = c.getTime();
        System.out.println(d);
        //Tue Jul 15 10:09:35 CST 2025
    }
}
